/**
 * @author brianxia
 * @version 1.0
 * @date 2022-10-22 15:35
 */
public class Demo5 {

    public static volatile int count = 0; //单例模式会用到

    //线程安全概念  案例线程不安全
    public static void main(String[] args) throws InterruptedException {

        Thread thread1 = new Thread(() -> {
            for (int i = 0; i < 100000; i++) {
                count++;
            }
        });

        Thread thread2 = new Thread(() -> {
            for (int i = 0; i < 100000; i++) {
                count++;
            }
        });

        thread1.start();
        thread2.start();

        //等待线程结束
        thread1.join();
        thread2.join();

        System.out.println(count);
    }
}
